package com.example.service_order.controller;

import com.example.common.commonsutils.R;
import com.example.service_order.service.PayLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author:tjf
 * @Description:
 */
@RestController
@RequestMapping("/orderservice")
@Tag(name = "支付控制器")
public class PayLogController {
    @Resource
    private PayLogService payLogService;
    @Operation(description = "根据订单号，获取微信支付二维码")
    @GetMapping("/wxpay/{orderNo}")
    public R createNative(@PathVariable("orderNo") String orderNo){
        Map<String, Object> map = payLogService.createNative(orderNo);
        return R.ok().data("result", map);
    }
    @Operation(description = "根据订单号，查询支付状态")
    @GetMapping("/paystatus/{orderNo}")
    public R queryWxPayStatus(@PathVariable("orderNo") String orderNo){
        String payStatus = payLogService.queryWxPayStatus(orderNo);
        if (StringUtils.isBlank(payStatus)){
            return R.error().code(25000).message("UNPAID");
        }
        return R.ok().message("PAID");
    }
}
